package com.bw.wxy.common;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.bw.wxy.R;

public class GlideUtils {
    public static GlideUtils glideUtils;

    private GlideUtils(){}

    public static GlideUtils getInstance(){
        if (glideUtils==null){
            glideUtils=new GlideUtils();
        }
        return glideUtils;
    }

    public void loadMatchImg(String url, ImageView img){
        Glide.with(img.getContext()).load(Api.FileUrl+url)
                .placeholder(R.mipmap.share_img_not)
                .error(R.mipmap.res_status_net_error)
                .transform(new CenterCrop(),new RoundedCorners(5))
                .into(img);
    }

    public static void loadCircleImg(String url, ImageView img){
        Glide.with(img.getContext())
                .load(Api.FileUrl+url)
                .error(R.mipmap.res_status_net_error)
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(img);
    }

    public static void loadRoundImg(String url, ImageView img,int radius){
        Glide.with(img.getContext())
                .load(Api.FileUrl+url)
                // 圆角效果
                .transform(new CenterCrop(),new RoundedCorners(radius))
                .into(img);
    }
}

